package com.du.mq.consumer.listen;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListenerBeanPostProcessor;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.lang.reflect.AnnotatedElement;
import java.util.Map;

/**
 * @Desc :
 * @Author: shuangdu
 * @date : 2022/5/9
 */
@RocketMQMessageListener(topic = "topic_mq", consumerGroup = "test-consumer-group", consumeMode = ConsumeMode.ORDERLY)
@Component
@Slf4j
public class TestListener implements RocketMQListener<String>, RocketMQMessageListenerBeanPostProcessor.AnnotationEnhancer {

    @Override
    public void onMessage(String s) {
      log.info("receive message: {}", s);
    }

    @Override
    public Map<String, Object> apply(Map<String, Object> stringObjectMap, AnnotatedElement annotatedElement) {
        stringObjectMap.put("user", "do");
        return stringObjectMap;
    }
}
